//========================================================================
// *作者：海盗猫  主页：ilplay.com
// *脚本：ToolBuildScriptPackage
// *描述：
// *?2021 MYJL . All rights reserved.
//* ======================================================================
#if UNITY_EDITOR
using UnityEngine;
using HDMCode.FrameEditor;
using UnityEditor;
namespace HDMCode.Hotfix
{
    public class DrawMeunSetting : ScriptableObject
    {
        [SerializeField]
        public string ScriptOutPutPath;
        [SerializeField]
        public string AssetsOutPutPath;
        [SerializeField]
        public string AssetsPackageName;
        [SerializeField]
        public string ScriptPackageName;
    }

    public class DrawMeun
    {
        /// <summary>
        /// 获取配置文件
        /// </summary>
        private static DrawMeunSetting _drawUISetting;
        public static DrawMeunSetting drawUISetting
        {
            get
            {
                if (_drawUISetting == null)
                {
                    _drawUISetting = AssetDatabase.LoadAssetAtPath<DrawMeunSetting>($"{PackedAssetsPath}/HDMHotfixSetting.asset");
                }
                return _drawUISetting;
            }
        }
        /// <summary>
        /// 资源打包配置文件，资源相对路径
        /// </summary>
        public static readonly string PackedAssetsPath = $"Packages/com.hdmframe.hotfix/Setting";

        /// <summary>
        /// 工具地址
        /// </summary>
        public static readonly string ToolAssetsPath = $"{System.Environment.CurrentDirectory}/Packages/HDMFrameHotfix/Tool~/HFSTool.exe";

        /// <summary>
        /// 资源打包配置文件，项目相对路径
        /// </summary>
        public static readonly string PackedProjectPath = $"{System.Environment.CurrentDirectory}/Packages/com.hdmframe.hotfix/Setting";

        [HDMCode.FrameEditor.HDMEditorMenu("热更新设置", "程序集设置", "HotterIcon.png")]
        public static void DrawHotFix()
        {
            HDMEditorHelper.DrawSettingIcon(() =>
            {
                HDMEditorHelper.CreatSetting<DrawMeunSetting>($"{PackedProjectPath}/HDMHotfixSetting.asset", $"{PackedAssetsPath}/HDMHotfixSetting.asset");
            });

            HDMEditorHelper.DrawTileLable("程序集路径设置");
            using (new EditorGUILayout.HorizontalScope())
            {
                GUILayout.Label("程序集输出路径", GUILayout.Width(100));
                EditorGUILayout.HelpBox(drawUISetting.ScriptOutPutPath,  MessageType.None);
                if (GUILayout.Button("选择", GUILayout.Width(50)))
                {
                    drawUISetting.ScriptOutPutPath = EditorUtility.OpenFolderPanel("选择路径", "", "");
                }
            }


            HDMEditorHelper.DrawTileLable("资源打包设置");
            using (new EditorGUILayout.HorizontalScope())
            {
                GUILayout.Label("资源打包设置", GUILayout.Width(100));
                EditorGUILayout.HelpBox(drawUISetting.AssetsOutPutPath, MessageType.None);
                if (GUILayout.Button("选择", GUILayout.Width(50)))
                {
                    drawUISetting.AssetsOutPutPath = EditorUtility.OpenFolderPanel("选择路径", "", "");
                }
            }

            HDMEditorHelper.DrawTileLable("热更新包体名称设置");
            using (new EditorGUILayout.HorizontalScope())
            {
                GUILayout.Label("资源包名称", GUILayout.Width(80));
                drawUISetting.AssetsPackageName = EditorGUILayout.TextField(drawUISetting.AssetsPackageName, GUILayout.Width(100));
                GUILayout.Space(30);
                GUILayout.Label("补丁包名称", GUILayout.Width(80));
                drawUISetting.ScriptPackageName = EditorGUILayout.TextField(drawUISetting.ScriptPackageName, GUILayout.Width(100));
            }

            if (GUI.changed)
                EditorUtility.SetDirty(drawUISetting);
        }
    }
}
#endif